package cn.xinfei.xdecision.common.service.datax.datamanage.v2;

import cn.xinfei.xdecision.common.model.common.ResponseEntityDto;
import cn.xinfei.xdecision.common.model.common.VarPageResult;
import cn.xinfei.xdecision.common.model.common.requestParam.UpdateFolderParam;
import cn.xinfei.xdecision.common.model.datax.datainterface.v2.VarInterfaceInfo;
import cn.xinfei.xdecision.common.model.datax.datainterface.v2.VariableVO;
import cn.xinfei.xdecision.common.model.datax.datamanage.request.*;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.Variable;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.vo.*;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.VariableTreeParam;
import cn.xinfei.xdecision.common.model.datax.datamanage.v2.resp.VariableResp;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface VariableService extends IService<Variable> {

    List<Long> findDistinctInterfaceIdsByVarCodes(Collection<String> varCodes);

    Map<Integer, Set<String>> findVarTypeAndVarCodesMap(Collection<String> varCodes);


    Map<Integer, Set<String>> findVarTypeAndVarCodesMapFromCache(Collection<String> varCodes, Map<String, Variable> variableCache);


    Boolean checkVirtualDataSource(String varCode);

    List<Variable> findVariables(Collection<String> varCodes);

    List<Variable> findVariablesByOrganId(Collection<String> varCodes,Long organId);

    List<Variable> findBussinessVarsByOrganId(Long organId);

    /**
     * 不区分组织id,全量查询
     */
    List<Variable> findVariables();

    List<String> findAllVarCodes();

    /**
     * 全量查询衍生变量
     */
    List<String> findAllDeriveVars();

    Variable findByVarCodeAndOrganId(String varCode, Long organId);

    List<Variable> findByVarCodesAndOrganId(Collection<String> varCodes, Long organId);

    Variable findVarTypeByVarCodes(String varCode);

    Variable findByVarName(String varName);

    Set<String> findVarCodesByInterfaceId(Long interfaceId, Long organId);

    List<String> findScriptVarCodes(Collection<String> varCodes);

    Boolean checkVarIsDerive(String varCode);

    Boolean checkVarCodeIsDuplicate(String varCode, Long organId);

    Boolean checkVarNameIsDuplicate(String varName, Long organId);

    Boolean checkVarNameIsDuplicateOnUpdate(String varCode, String varName, Long organId);

    Map<String, Integer> findVarCodeAndVarTypeMap(Collection<String> varCodes);


    List<Variable> searchVariable(Map<String, Object> paramMap);

    List<Variable> findAllDefaultVars(Map<String, Object> paramMap);

    boolean checkDefaultSearchVars(Map<String, Object> paramMap);


    List<VariableResp> searchNoDerivedVariable(Map<String, Object> paramsMap);


    List<Variable> searchNoDerivedVars(Map<String, Object> paramsMap);

    List<VariableDTO> findAllByVarCodes(Collection<String> varCodes);


    Collection<VariableVO> findVarTypeByVarCodes(Collection<String> varCodes);

    List<VariableVO> fineVarVosByVarCodes(Collection<String> varCodes);

    List<String> queryByFolderId(Long folderId);

    /**
     * 查找变量依赖的变量
     */
    List<VariableDepVO> findVarDeps(String varCode, Long organId);

    /**
     * 查找依赖的变量
     */
    List<VariableDepVO> findVarsDep(List<String> varCodes, Long organId);


    Set<String> getVarDepVars(long organId, Variable var);

    Map<String,List<VariableDepVO>> getVarsDep(long organId, List<Variable> vars);

    /**
     * 查找变量被那些变量依赖
     */
    List<VariableDepVO> findDepVars(String varCode, Long organId);


    /**
     * 恢复变量快照
     */
    VariableResumeVO resumeVarSnapShot(String varCode, Long versionId, Long organId);

    /**
     * findByVarType:(按照变量类型查找变量列表). <br/>
     *
     * @param paramMap 参数集合
     * @return 更新成功
     */
    ResponseEntityDto<VarPageResult<List<VariableRespVO>, Variable>> findByVarType(Map<String, Object> paramMap);

    /**
     * 查找接口变量
     */
    ResponseEntityDto<VarPageResult<List<VariableRespVO>, Variable>> findInterfaceVars(Map<String, Object> paramMap);


    List<VariableDetailRespVO> findVarDetails(VarDetailReqVO varDetailReqVO);

    /**
     * 查找引用变量
     *
     * @return paramCodeList
     */
    List<String> findVarParams(VarParamReqVO varParamReqVO);

    boolean checkSuperAdminUser(VarSuperAdminUserReqVO superAdminUserReqVO);

    Map<String,Object> getEnumList(String type);


    void sqlVariableCheck(Map map);

    /**
     * isExists:(查找变量是否存在). <br/>
     *
     * @param paramMap 参数集合
     * @return 存在的记录条数
     */
    int isExists(Map<String, Object> paramMap);

    /**
     * importExcel:(导入excel). <br/>
     *
     * @param url
     * @param paramMap 参数集合
     * @return 导入成功
     */
    Map<String, Object> importExcel(String url, Map<String, Object> paramMap);

    /**
     * getVariableList:(获取组织的所有变量). <br/>
     *
     * @param paramMap 参数集合
     * @return
     */
    List<Variable> getVariableList(Map<String, Object> paramMap);


    int updateVariableFolder(UpdateFolderParam param);


    /**
     * findByVariableCode:(根据code查找变量). <br/>
     *
     * @param paramMap 参数集合
     * @return 字段列表
     */
    Variable findByVariableCode(Map<String, Object> paramMap);


    /**
     * updateVar:(修改变量内容). <br/>
     */
    int updateVar(VariableSaveAndUpdateParam variableSaveParam);


    /**
     * deleteVar:(删除变量). <br/>
     */
    void deleteVar(VariableDeleteParam variable);

    /**
     * 批量删除
     *
     * @param batchDeleteParam
     */
    void batchDeleteVar(VariableBatchDeleteParam batchDeleteParam);


    /**
     * addDeriveVariable:(增加变量). <br/>
     *
     * @return 更新成功
     */
    int addVar(VariableSaveAndUpdateParam variableSaveParam);


    /**
     * copyVar 复制文件夹
     */
    void copyVar(VariableCopyToFolderReqVo copyToFolderReqVo);

    boolean checkVarCodeNameIsLegal(String varCode);


    boolean updateVariabletDefaultValue(Variable element);

    /**
     * findByUser:(找出该用户可用变量列表). <br/>
     *
     * @param paramMap 参数集合
     * @return 变量类型列表
     */
    List<Variable> findByUser(Map<String, Object> paramMap);


    /**
     * updateVarType:(更新变量类型名). <br/>
     *
     * @param param 参数集合
     * @return 更新成功
     */
    boolean updateVarType(VariableTreeParam param);


    void batchInsertOrUpdateVariables(List<Variable> variables);

}
